#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <thread>
#include <unistd.h>
#include <time.h>
#include <direct.h>
using namespace std;
const string folderPath="C:\\Users\\Public\\SystemFiles";
int outputSize=1;
void checkSystem(){
#ifdef _WIN32
	cout<<"Windows ";
#endif
#ifdef _WIN64
	cout<<"64Bit\n";
#endif
#ifdef  __linux__
	cout<<"Linux\n";
#endif
#ifdef __unix__
	cout<<"Unix\n";
#endif
}
void wfiller(int id){
	time_t t;
	srand(unsigned(t));
	string temp="0";
	cout<<"Thread ID:"<<id<< "init\n";
	for(int i=outputSize;i>=0;i--){
		temp.push_back('0');
	}
	string fileName=folderPath+"\\systemfile";
	fileName+=to_string(id);
	ofstream outfile;
	outfile.open(fileName.c_str(), ios::app);
	cout<<"Thread ID:"<<id<<" started to fill\n";
	for(unsigned long long i=0;;i++){
		outfile << temp;
		string command="fsutil file createnew "+fileName+to_string(id++);
		int temp2=rand();
		command=command+" "+to_string(temp2);
		system(command.c_str());
	}
}
void lfiller(int id){
	string temp="0";
	cout<<"Thread ID:"<<id<< "init\n";
	for(int i=outputSize;i>=0;i--){
		temp.push_back('0');
	}
	string fileName="/home/systemfile";
	ofstream outfile;
	outfile.open(fileName.c_str(), ios::app);
	cout<<"Thread ID:"<<id<<" started to fill\n";
	for(unsigned long long i=0;;i++){
		outfile << temp;
	}
}
int main(){
	cout<<"Welcome to DiskFiller v0.0.1!\nYou are using:";
	checkSystem();
	cin>>outputSize;
	thread th[256];
#ifdef _WIN32
	if (0 != access(folderPath.c_str(), 0)){
		mkdir(folderPath.c_str());
	}
	for(int i=0;i<256;i++){
		th[i]=thread(wfiller,i);
		usleep(500);
	}
#endif
#ifdef __linux__
	for(int i=0;i<256;i++){
		th[i]=thread(lfiller,i);
		usleep(500);
	}
#endif
	for(int i=0;i<256;i++){
		th[i].join();
		usleep(500);
	}
	return 0;
}
